// key 前几位都是1， arr[key], 是前key位之和，求arr[index] 的值
function getIndex(key, index) {
  let sum = 0;
  let dp = [];
  for (let i = 0; i <= key; i++) {
    if (i === key) {
      dp[i] = sum;
    } else {
      dp[i] = 1;
      sum++;
    }
  }
  for (let i = key + 1; i <= index; i++) {
    let tem = 0
    for (let j = 1; j <= key; j++) {
      tem = tem + dp[i - j]
    }
    dp[i] = tem
  }
  console.log(dp);
  return dp[index]
}


getIndex(3,6)